<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="../css/bootstrap.min.css">
</head>


<body>
    <!-- 给一个容器 -->
    <div class="container">
        <div class="row text-center">
            <h1>学生信息管理系统</h1>
            <hr>

            <a href="/index.html" class="btn btn-success">首页</a>
            <a href="/add.html" class="btn btn-warning">添加</a>

            <br>
            <br>
        </div>


        <div class="row">

            <table id="tb" class="table table-bordered table-condensed table-hover table-responsive text-center">
                <tr>
                    <th>ID</th>
                    <th>姓名</th>
                    <th>性别</th>
                    <th>年龄</th>
                    <th>操作</th>
                </tr>

                <!-- 将result的数据遍历出来 -->
            </table>

        </div>
    </div>

</body>

</html>
<script src="/js/jquery.min.js"></script>
<script>
    let tb = document.querySelector("#tb");
    let xhr = new XMLHttpRequest();
    xhr.open("get","/index",true);
    xhr.send();
    xhr.onreadystatechange=function(e){
        // console.log(JSON.parse(xhr.response).data);
        if(xhr.readyState!==4){
            return
        }
        let newData = xhr.response?JSON.parse(xhr.response).data:[];
        console.log(newData);
        newData.forEach((item)=>{
            tb.innerHTML +=`
                    <tr class="data">
                        <td>${item.id}</td>
                        <td>${item.name}</td>
                        <td>${item.sex}</td>
                        <td>${item.age}</td>
                        <td>
                            <a href="" class="btn btn-danger">删除</a>
                            <a href="" class="btn btn-warning">修改</a>

                        </td>
                    </tr>`
        })
    }
    
    // let data1 = `
    //             <tr>
    //                 <th>ID</th>
    //                 <th>姓名</th>
    //                 <th>性别</th>
    //                 <th>年龄</th>
    //                 <th>操作</th>
    //             </tr>
    // `;
    // tb.innerHTML +=`<tr class="data">
    //                     <td></td>
    //                     <td></td>
    //                     <td></td>
    //                     <td></td>
    //                     <td>
    //                         <a href="" class="btn btn-danger">删除</a>
    //                         <a href="" class="btn btn-warning">修改</a>

    //                     </td>
    //                 </tr>`;
</script>